﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace FluentDml.Linq
{
    public static class HqlWhereClauseGenerator
    {
        public static HqlCommand Generate(ParameterAggregator parameterAggregator, Expression where)
        {
            //get the value if possible
            var partialEval = Evaluator.PartialEval(where);

            HqlGeneratorExpressionTreeVisitor visitor = new HqlGeneratorExpressionTreeVisitor(parameterAggregator);
            visitor.VisitExpression(partialEval);

            return new HqlCommand(visitor.GetHqlExpression(), visitor.SubQueryReconmended);
        }
    }

    public class HqlCommand
    {
        public HqlCommand(string hql, bool isSubQuery)
        {
            Hql = hql;
            IsSubQuery = isSubQuery;
        }

        public string Hql { get; private set; }
        public bool IsSubQuery { get; private set; }
    }

}

